import unittest
from PySendForRad.模拟器 import check_port_availability  # Assuming this is the correct import path


class TestCheckPortAvailability(unittest.TestCase):

    def test_check_port_availability_available(self):
        """
        Test that the function returns True when the port is available.
        """
        with self.assertLogs() as cm:
            self.assertFalse(check_port_availability('localhost', 3306))
        # Check if the function logs a message when the port is available
        self.assertEqual(cm.output, "")

    def test_check_port_availability_unavailable(self):
        """
        Test that the function returns False when the port is not available.
        """
        with self.assertLogs() as cm:
            self.assertFalse(check_port_availability('localhost', 9527))
        # Check if the function logs a message when the port is not available
        self.assertIn("Address already in use", cm.output)


if __name__ == '__main__':
    unittest.main()
